{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4ff24f48",
   "metadata": {},
   "outputs": [],
   "source": [
    "上节课回顾"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "5ac04c3d",
   "metadata": {},
   "outputs": [],
   "source": [
    "name = \"chaichai\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "e4444dba",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Chaichai'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name.capitalize()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "91d6016a",
   "metadata": {},
   "source": [
    "-------\n",
    "* 2022/09/20 /week05\n",
    "* python 课堂笔记"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f8327bdb",
   "metadata": {},
   "source": [
    "# 本周内容 \n",
    "> 1.有序的数据结构之列表\n",
    "\n",
    "> 2.用户输入\n",
    "\n",
    "> 3.关于格式化文本信息"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "395035a1",
   "metadata": {},
   "outputs": [],
   "source": [
    "网三_01_name = \"Marry\"\n",
    "\n",
    "# 思考：如果想一个变量存放一个班同学的名字，该怎么存？\n",
    "# 思考：处理数据会不会比较麻烦？"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "85c9a6db",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Marry,Alex,Jack,周晓明\n"
     ]
    }
   ],
   "source": [
    "网三_name_list = \"Marry,Alex,Jack,周晓明\"\n",
    "print(网三_name_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "df8932bd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Alex'"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 思考：处理数据会不会比较麻烦？\n",
    "网三_name_list[6:10]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "3ad8c6a3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "19"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 思考：我想知道这个名单有多少个人名？\n",
    "len(网三_name_list)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "75787991",
   "metadata": {},
   "source": [
    "## 1.引入列表的概念\n",
    "* Lists might contain items of different types, but usually the items all have the same type\n",
    "> 注释:我们已经学习了   数值  和   字符，list可以放数值和字符，但是通常要么一起放数值，要么一起放字符串。\n",
    "\n",
    "\n",
    "> 总结一些通用的有序数据结构的方法：\n",
    ">> 1. 取值：通过索引值取出对应的内容\n",
    ">> 2. 切片：通过索引值区间取出对应的一些内容\n",
    ">> 3. in 可以查看成员对象是否存在\n",
    "\n",
    "> 列表的一些方法："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "3c668cb2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 3, 4] <class 'list'>\n"
     ]
    }
   ],
   "source": [
    "a = [1,2,3,4]\n",
    "print(a,type(a))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "c1b0e88f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Marry', 'Alex', 'Jack', '周晓明'] <class 'list'>\n"
     ]
    }
   ],
   "source": [
    "网三_name_list = [\"Marry\",\"Alex\",\"Jack\",\"周晓明\"]\n",
    "print(网三_name_list,type(网三_name_list))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7925be00",
   "metadata": {},
   "source": [
    "# 练习"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "edf26d78",
   "metadata": {},
   "source": [
    "* 说唱新世代"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "81a8ee43",
   "metadata": {},
   "outputs": [],
   "source": [
    "说唱新世代 = [\"沙一汀\",\"小精灵\",\"ty\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "7ac104e0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['沙一汀', '小精灵', 'ty']"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "说唱新世代"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "346bdf5f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(说唱新世代)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "896d0826",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'沙一汀'"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "说唱新世代[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "b193cbb8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "沙一汀\n",
      "小精灵\n",
      "ty\n"
     ]
    }
   ],
   "source": [
    "for i in 说唱新世代:\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "afd3c335",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "帅哥： 沙一汀\n",
      "帅哥： 小精灵\n",
      "帅哥： ty\n"
     ]
    }
   ],
   "source": [
    "for i in 说唱新世代:\n",
    "    print(\"帅哥：\",i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "ed1f32b5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"沙一汀\" in 说唱新世代"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "035b6da0",
   "metadata": {},
   "outputs": [],
   "source": [
    "说唱新世代.append(\"姜云升\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "8334a0c6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['沙一汀', '马思维', '马思维', '小精灵', 'ty', '姜云升', '姜云升']"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "说唱新世代"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "0f6c02e0",
   "metadata": {},
   "outputs": [],
   "source": [
    "说唱新世代.insert(5,\"KNOWKNOW\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "677f47e0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['沙一汀', '马思维', '马思维', '小精灵', 'ty', 'KNOWKNOW', '姜云升', '姜云升']"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "说唱新世代"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "915ffeec",
   "metadata": {},
   "outputs": [],
   "source": [
    "说唱新世代.remove(\"马思维\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "71c60ec0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['沙一汀', '马思维', '小精灵', 'ty', 'KNOWKNOW', '姜云升', '姜云升']"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "说唱新世代"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "3ee954b8",
   "metadata": {},
   "outputs": [],
   "source": [
    "说唱新世代.remove(\"姜云升\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "c3ef768c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['沙一汀', '马思维', '小精灵', 'ty', 'KNOWKNOW', '姜云升']"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "说唱新世代"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "id": "6e679b46",
   "metadata": {},
   "outputs": [],
   "source": [
    "说唱新世代.remove(\"沙一汀\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "id": "dee8e3cc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['马思维', '小精灵', 'ty', 'KNOWKNOW', '姜云升']"
      ]
     },
     "execution_count": 71,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "说唱新世代"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "aebd03e0",
   "metadata": {},
   "source": [
    "* 说唱巅峰对决"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 116,
   "id": "eef73fc9",
   "metadata": {},
   "outputs": [],
   "source": [
    "说唱巅峰对决 = \"刘聪，王以太，早安\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 117,
   "id": "aa3e938e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'刘聪，王以太，早安'"
      ]
     },
     "execution_count": 117,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "说唱巅峰对决"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 118,
   "id": "9d9896c7",
   "metadata": {},
   "outputs": [],
   "source": [
    "说唱巅峰对决 = [\"刘聪\",\"王以太\",\"早安\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 119,
   "id": "d470c323",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['马思维', '小精灵', 'ty', 'KNOWKNOW', '姜云升', '刘聪', '王以太', '早安']"
      ]
     },
     "execution_count": 119,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "说唱新世代 + 说唱巅峰对决"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 120,
   "id": "d13f6f04",
   "metadata": {},
   "outputs": [],
   "source": [
    "说唱巅峰对决.append(\"羊和苏\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 121,
   "id": "e4fe719e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['刘聪', '王以太', '早安', '羊和苏']"
      ]
     },
     "execution_count": 121,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "说唱巅峰对决"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 123,
   "id": "323fde34",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['王以太', '早安', '羊和苏']"
      ]
     },
     "execution_count": 123,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "if \"刘聪\" in 说唱巅峰对决:\n",
    "    说唱巅峰对决.remove(\"刘聪\")\n",
    "说唱巅峰对决"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 162,
   "id": "b349f03d",
   "metadata": {},
   "outputs": [],
   "source": [
    "说唱巅峰对决.append(\"羊和苏\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 163,
   "id": "f7dbbf8f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['王以太', '早安', '羊和苏', '羊和苏']"
      ]
     },
     "execution_count": 163,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "说唱巅峰对决"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 167,
   "id": "9e2fdfba",
   "metadata": {},
   "outputs": [],
   "source": [
    "说唱巅峰对决 = [\"王以太\",\"早安\",\"羊和苏\",\"羊和苏\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 170,
   "id": "0bd411c9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 170,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "说唱巅峰对决.count(\"羊和苏\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a52bcc22",
   "metadata": {},
   "source": [
    "* 快乐大本营"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 145,
   "id": "82325c43",
   "metadata": {},
   "outputs": [],
   "source": [
    "快乐大本营 =[\"吴昕，谢娜，何炅，杜海涛，维嘉\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 146,
   "id": "85170149",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['吴昕，谢娜，何炅，杜海涛，维嘉']"
      ]
     },
     "execution_count": 146,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "快乐大本营"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 147,
   "id": "94712949",
   "metadata": {},
   "outputs": [],
   "source": [
    "快乐大本营.insert(1,\"xiaolan\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 148,
   "id": "1890061b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['吴昕，谢娜，何炅，杜海涛，维嘉', 'xiaolan']"
      ]
     },
     "execution_count": 148,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "快乐大本营"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 149,
   "id": "d2b9f849",
   "metadata": {},
   "outputs": [],
   "source": [
    "快乐大本营.remove(\"xiaolan\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 150,
   "id": "b36fa385",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['吴昕，谢娜，何炅，杜海涛，维嘉']"
      ]
     },
     "execution_count": 150,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "快乐大本营"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 155,
   "id": "271072a5",
   "metadata": {},
   "outputs": [],
   "source": [
    "快乐大本营 = [\"吴昕\",\"何炅\",\"谢娜\",\"维嘉\",\"海涛\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 156,
   "id": "179d98d3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'海涛'"
      ]
     },
     "execution_count": 156,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "快乐大本营.pop()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 157,
   "id": "35ccf417",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'谢娜'"
      ]
     },
     "execution_count": 157,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "快乐大本营.pop(2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 158,
   "id": "2a056231",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['吴昕', '何炅', '维嘉']"
      ]
     },
     "execution_count": 158,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "快乐大本营"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "ece5a303",
   "metadata": {},
   "outputs": [],
   "source": [
    "快乐大本营 = [\"谢娜\",\"吴昕\",\"吴昕\",\"何炅\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "2b064eb4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "快乐大本营.count(\"吴昕\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "1982b8db",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['谢娜', '何炅']"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "删除的数量 = 快乐大本营.count(\"吴昕\")\n",
    "for i in range(删除的数量):\n",
    "    if \"吴昕\" in 快乐大本营:\n",
    "        快乐大本营.remove(\"吴昕\")\n",
    "    快乐大本营\n",
    "快乐大本营"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "86a259a5",
   "metadata": {},
   "source": [
    "* 问题？"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "ad1684de",
   "metadata": {},
   "outputs": [],
   "source": [
    "快乐大本营 = [\"吴昕\",\"吴昕\",\"谢娜\",\"何炅\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "74e626a3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 吴昕\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "['吴昕', '谢娜', '何炅']"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "for i,v in enumerate(快乐大本营):\n",
    "    if v == \"吴昕\":\n",
    "        print(i,v)\n",
    "        快乐大本营.pop(i)\n",
    "快乐大本营\n",
    "    "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7e276c38",
   "metadata": {},
   "source": [
    "## 1.1 列表的运算法则（operation）\n",
    " * <font color = \"red\"> 列表的数据本身不做修改</font>\n",
    " * 列表的运算法则不会改变列表本身的形态"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "678dc443",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Marry'"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 取出 网三_name_list 中第一位同学的名字\n",
    "网三_name_list[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "08c11ca8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 查看 网三_name_list  有多少位同学\n",
    "len(网三_name_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "098588bc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "网三: Marry\n",
      "网三: Alex\n",
      "网三: Jack\n",
      "网三: 周晓明\n"
     ]
    }
   ],
   "source": [
    "for i in 网三_name_list:\n",
    "    print(\"网三:\",i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "f9327dd7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# in 可以查询数据是否存在\n",
    "\"Jack\" in 网三_name_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "506c04f4",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 关于运算法则(in + 切片 取值 len（s） s.count )\n",
    "网三_name_list_转专业 = [\"Xiaoming\",\"Lihua\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "58bb71a5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Marry', 'Alex', 'Jack', '周晓明', 'Xiaoming', 'Lihua']"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网三_name_list + 网三_name_list_转专业"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "1fdf12bd",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 思考：一个list 可不可以出现重复项？\n",
    "网一_age_list = [18,19,19,18,20,19] \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "e4490f32",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[18, 19, 19, 18, 20, 19]"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网一_age_list"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7b3deb19",
   "metadata": {},
   "source": [
    "## 2.2列表的方法（Function）--对列表数据进行操作\n",
    ">  1. 增（append)(insert)\n",
    ">  2. 删 (remove-次数)(pop-位置）\n",
    ">  3. 改 \n",
    ">  4. 查"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "675e6625",
   "metadata": {},
   "outputs": [],
   "source": [
    "# append 增加，  增加元素到末尾"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "78eee1e2",
   "metadata": {},
   "outputs": [],
   "source": [
    "网三_name_list = [\"Marry\",\"Alex\",\"Jack\",\"周晓明\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "139c6649",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Marry', 'Alex', 'Jack', '周晓明']"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网三_name_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "96130bdf",
   "metadata": {},
   "outputs": [],
   "source": [
    "网三_name_list.append(\"张志豪\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "2ded4b49",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Marry', 'Alex', 'Jack', '周晓明', '张志豪']"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网三_name_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "id": "992ee0fd",
   "metadata": {},
   "outputs": [],
   "source": [
    "网三_name_list.append(\"王一鸣\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "5afe9a5e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Marry', 'Alex', 'Jack', '周晓明', '张志豪', '王一鸣']"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网三_name_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "id": "34d0b4a4",
   "metadata": {},
   "outputs": [],
   "source": [
    "#insert  增加元素到某个位置"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "id": "22086a8f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function insert:\n",
      "\n",
      "insert(index, object, /) method of builtins.list instance\n",
      "    Insert object before index.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(网三_name_list.insert)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "id": "9ebe143a",
   "metadata": {},
   "outputs": [],
   "source": [
    "网三_name_list.insert(1,\"李华\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "id": "3d8e681f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Marry', '李华', 'Alex', 'Jack', '周晓明', '张志豪', '王一鸣']"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网三_name_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "240567cb",
   "metadata": {},
   "outputs": [],
   "source": [
    "# remove"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "id": "44b3ee92",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function remove:\n",
      "\n",
      "remove(value, /) method of builtins.list instance\n",
      "    Remove first occurrence of value.\n",
      "    \n",
      "    Raises ValueError if the value is not present.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(网三_name_list.remove)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "id": "09e71199",
   "metadata": {},
   "outputs": [],
   "source": [
    "网三_name_list.remove('Alex')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "id": "6498d455",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Marry', '李华', 'Jack', '周晓明', '张志豪', '王一鸣']"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网三_name_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "id": "dcf7ed1a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Marry', '李华', 'Jack', '周晓明', '张志豪', '王一鸣']"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# remove  经常和 in 一起使用，先检查成员变量是否存在，然后再remove\n",
    "if \"Alex\" in 网三_name_list :\n",
    "    网三_name_list.remove(\"Alex\")\n",
    "网三_name_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dd0e7d27",
   "metadata": {},
   "outputs": [],
   "source": [
    "#pop"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "id": "6ac1f83c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function pop:\n",
      "\n",
      "pop(index=-1, /) method of builtins.list instance\n",
      "    Remove and return item at index (default last).\n",
      "    \n",
      "    Raises IndexError if list is empty or index is out of range.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(网三_name_list.pop)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 159,
   "id": "c5ddf6ef",
   "metadata": {},
   "outputs": [],
   "source": [
    "网三_name_list = ['Marry', '李华', 'Jack', '周晓明', '张志豪', '王一鸣']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 160,
   "id": "8eb036a6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'王一鸣'"
      ]
     },
     "execution_count": 160,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网三_name_list.pop()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 161,
   "id": "c40a669d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Jack'"
      ]
     },
     "execution_count": 161,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网三_name_list.pop(2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "5454d220",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 实践：请移除19的元素\n",
    "age_list = [18,19,18,19,17,20,20,18,19,16,17,20]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "206ec279",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "age_list.count(19)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "43896ba4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[18, 18, 17, 20, 20, 18, 16, 17, 20]"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 思路1：  remove(value)，先决条件,知道值出现的次数\n",
    "删除的数量 = age_list.count(19)\n",
    "for i in range(删除的数量):\n",
    "    if 19 in age_list:\n",
    "        age_list.remove(19)\n",
    "    age_list\n",
    "age_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "27db244e",
   "metadata": {},
   "outputs": [],
   "source": [
    "age_list = [18,19,18,19,17,20,20,18,19,16,17,20]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "1b75c815",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[18, 19, 18, 19, 17, 20, 20, 18, 19, 16, 17, 20]"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "age_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 98,
   "id": "81632a14",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 19\n",
      "2 19\n",
      "6 19\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[18, 18, 17, 20, 20, 18, 16, 17, 20]"
      ]
     },
     "execution_count": 98,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 思路2：pop(index),先决条件，知道值出现的位置\n",
    "for i,v in enumerate(age_list):\n",
    "    if v == 19:\n",
    "        print(i,v)\n",
    "        age_list.pop(i)\n",
    "age_list \n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a790f73f",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 课后练习：\n",
    "# 1.课本p68和p81\n",
    "# 2.剩下的reserve,extend,clear,copy,sbrt回去之后尝试练习\n",
    "# 3.总结列表的方法，用表格的形式写在markdown上面"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2667ca35",
   "metadata": {},
   "source": [
    "* 课后练习"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1f68025c",
   "metadata": {},
   "source": [
    "* 1.课本p68和p91"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "28000ad8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Don't panic!\n",
      "['D', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c', '!']\n"
     ]
    }
   ],
   "source": [
    "phrase = \"Don't panic!\"\n",
    "plist = list(phrase)\n",
    "print(phrase)\n",
    "print(plist)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "575351cb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['D', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c', '!']\n",
      "Don't panic!\n"
     ]
    }
   ],
   "source": [
    "new_phrase = ''.join(plist)\n",
    "print(plist)\n",
    "print(new_phrase)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "5b9c057b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Ford Prefect', 'Male', 'Researcher', 'Betelgeuse Seven']"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    ">>> person1 = ['Ford Prefect','Male','Researcher','Betelgeuse Seven']\n",
    ">>> person1\n",
    "['Ford Prefect','Male','Researcher','Betelgeuse Seven']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "6df4c650",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Name',\n",
       " 'Ford Prefect',\n",
       " 'Gender',\n",
       " 'Male',\n",
       " 'Occupation',\n",
       " 'Researcher',\n",
       " 'Home Planet',\n",
       " 'Betelgeuse Seven']"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    ">>> person2 = ['Name','Ford Prefect','Gender','Male','Occupation','Researcher','Home Planet','Betelgeuse Seven']\n",
    ">>> person2\n",
    "['Name','Ford Prefect','Gender','Male','Occupation','Researcher','Home Planet','Betelgeuse Seven']"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6220ac3e",
   "metadata": {},
   "source": [
    "* 2.剩下的reserve,extend,clear,copy,sbrt回去之后尝试练习"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "0ac18b79",
   "metadata": {},
   "outputs": [],
   "source": [
    "七朵金花_list =[\"蔡梓涵\",\"沈丹菁\",\"林馥星\",\"林宛欢\",\"李怡蕾\",\"郭欣腾\",\"黄鹭\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "5c108846",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['蔡梓涵', '沈丹菁', '林馥星', '林宛欢', '李怡蕾', '郭欣腾', '黄鹭']"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "七朵金花_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "ffdc3d08",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function extend:\n",
      "\n",
      "extend(iterable, /) method of builtins.list instance\n",
      "    Extend list by appending elements from the iterable.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(七朵金花_list.extend)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "71fc3da9",
   "metadata": {},
   "outputs": [],
   "source": [
    "七朵金花_list.extend(\"谢仲杰\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "5650b513",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['蔡梓涵', '沈丹菁', '林馥星', '林宛欢', '李怡蕾', '郭欣腾', '黄鹭', '谢', '仲', '杰']"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "七朵金花_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "427410e7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function copy:\n",
      "\n",
      "copy() method of builtins.list instance\n",
      "    Return a shallow copy of the list.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(七朵金花_list.copy)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "e4e81178",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['蔡梓涵', '沈丹菁', '林馥星', '林宛欢', '李怡蕾', '郭欣腾', '黄鹭', '谢', '仲', '杰']"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "七朵金花_list.copy()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4c1804e6",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
